﻿Imports MySql.Data.MySqlClient
Public Class frmedit_vessel
    Dim mysql As MySqlConnection = main_form.mysqlconection
    Dim mySqlCommand As New MySqlCommand
    Dim mySqlAdaptor As New MySqlDataAdapter
    Dim mySqlReader As MySqlDataReader
    Dim respone As Object
    Private Sub frmedit_vessel_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US")
        System.Threading.Thread.CurrentThread.CurrentUICulture = System.Threading.Thread.CurrentThread.CurrentCulture
        mysql.Close()
        If mysql.State = ConnectionState.Closed Then
            mysql.Open()
        End If
        mySqlCommand.CommandText = "Select * from vesmain where VESMAINID ='" & frmsearch_vessel.idvessel & "' ;"
        ' mySqlCommand.CommandText = 
        mySqlCommand.Connection = mysql
        mySqlAdaptor.SelectCommand = mySqlCommand

        Try
            mySqlReader = mySqlCommand.ExecuteReader

            While (mySqlReader.Read())
                txt_vessel.Text = mySqlReader("VSSNAM")
                txt_namemaster.Text = mySqlReader("VSSMASTER")
                txt_nationality.Text = mySqlReader("VSSNATION")
                txt_insurance.Text = mySqlReader("VSSINS")


         
                date_eta.Text = mySqlReader("VSSDATE")

            End While
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        mysql.Close()
    End Sub

    Private Sub ButtonX1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonX1.Click
        mysql.Close()
        If mysql.State = ConnectionState.Closed Then
            mysql.Open()
        End If
        Try
            Dim commandText2 As String
            commandText2 = "UPDATE vesmain SET VSSNAM = '" & txt_vessel.Text & "' , VSSMASTER = '" & txt_namemaster.Text & "' , VSSNATION = '" & txt_nationality.Text & "' , VSSINS = '" & txt_insurance.Text & "',VSSDATE ='" & date_eta.Text & "'  WHERE VESMAINID = " & frmsearch_vessel.idvessel & "; "
            mySqlCommand.CommandText = commandText2
            mySqlCommand.CommandType = CommandType.Text
            mySqlCommand.Connection = mysql

            mySqlCommand.ExecuteNonQuery()
            mysql.Close()

            MsgBox("แก้ไขข้อเรียบร้อย")
            Dim cf As New frmsearch_vessel

            cf.MdiParent = Me.MdiParent
            Me.Close()
            cf.Dock = DockStyle.Fill
            cf.Show()
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

    Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click

    End Sub

    Private Sub Label6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label6.Click

    End Sub
End Class